package com.tiancheng.trade.commom.core.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 划付、分账状态
 *
 * @author DCH
 * @date 2024/11/5
 */
@Getter
@AllArgsConstructor
public enum SettleStatusEnum implements BaseEnum<String> {

    WAIT("WAIT", "待清分"),
    ING("ING", "进行中"),
    SUCCESS("SUCCESS", "成功"),
    PART_SUCCESS("PART_SUCCESS", "部分成功"),
    FAIL("FAIL", "失败");

    private final String code;
    private final String desc;

    public static String getDesc(String code) {
        Optional<SettleStatusEnum> found = Arrays.stream(SettleStatusEnum.values()).filter(c -> c.code.equals(code)).findFirst();
        if (found.isPresent()) {
            return found.get().getDesc();
        }
        return "";
    }

    /**
     * 转换银联返回的状态码
      * @param code
     * @return
     */
    public static SettleStatusEnum getCodeByUmsCode(String code) {
        SettleStatusEnum statusEnum = null;
        switch (code) {
            case "0":
                statusEnum = SettleStatusEnum.FAIL;
                break;
            case "1":
                statusEnum = SettleStatusEnum.SUCCESS;
                break;
            case "2":
                statusEnum = SettleStatusEnum.PART_SUCCESS;
                break;
            case "3":
                statusEnum = SettleStatusEnum.ING;
                break;
            case "4":
                statusEnum = SettleStatusEnum.WAIT;
        }
        return statusEnum;
    }
}
